/**
 * Created by new on 2017/5/22.
 */
$(document).ready(function () {

    $.jgrid.defaults.styleUI = 'Bootstrap';

    $("#table_list_2").jqGrid({
        // data: mydata,
        url: '/admin/bridge/list',
        editurl: '/admin/bridge/update',
        closeAfterEdit: true,
        datatype: "json",
        height: 425,
        mtype:"GET",
        autowidth: true,
        shrinkToFit: true,
        rowNum: 20,
        rowList: [10, 20, 30],
        colNames: ["序号","桥梁名称","街道","起点","终点","建设年代","桥梁属性","桥梁材质","权属单位"	,"检测评定等级","检测单位","检测时间"],
        colModel: [
            {name: 'id', index: 'id', editable: true, width: 15, sortType: "int", search: true, align: "center",editoptions:{readonly:true}},
            {name: 'bridgeName', index: 'bridgeName', editable: true, width: 40, align: "center",editrules:{required:true}},
            {name: 'street', index: 'street', editable: true, width: 30, align: "center",editrules:{required:true}},
            {name: 'startName', index: 'startName', editable: true, width: 30, align: "center",editrules:{required:true}},
            {name: 'endName', index: 'endName', editable: true, width: 30, align: "center",editrules:{required:true}},
            {name: 'buildYear', index: 'buildYear', editable: true, width:25, sortable: false, align: "center", editrules:{required:true}},
            {name: 'bridgeAttribute', index: 'bridgeAttribute', editable: true, width: 30, align: "center",editrules:{required:true}},
            {name: 'bridgeTexture', index: 'bridgeTexture', editable: true, width: 30, align: "center",editrules:{required:true}},
            {name: 'ownership', index: 'ownership', editable: true, width: 45, align: "center",editrules:{required:true}},
            {name: 'checkRank', index: 'checkRank', editable: true, width: 30, align: "center"},
            {name: 'checkUnit', index: 'checkUnit', editable: true, width: 45, align: "center"},
            {name: 'checkTime', index: 'checkTime', editable: true, width: 30, align: "center", formatter:"date",formatoptions: {newformat:'Y-m-d'}}
        ],
        pager: "#pager_list_2",
        viewrecords: true,
        caption: "桥梁数据",
        add: true,
        edit: true,
        addtext: 'Add',
        edittext: 'Edit',
        hidegrid: false,
        jsonReader: {
            root: "data.list",
            page: "data.currPage",
            total: "data.totalPage",
            records: "data.totalCount"
        },
        prmNames: {
            page: "page",
            rows: "limit",
            order: "sord"
        }
    });

        // Add selection
    $("#table_list_2").setSelection(4, true);


    // Setup buttons
    $("#table_list_2").jqGrid('navGrid', '#pager_list_2', {
        editurl: true,
        addurl: true,
        delurl: true,
        searchurl: true,
        refresh:true
    }, {
        height: 200,
        reloadAfterSubmit: true
    },{
        url: '/admin/bridge/save',
        closeAfterAdd: true
    },{
        url: '/admin/bridge/delete',
        closeAfterDelete: true
    },{
        url: '/admin/bridge/search',
        closeAfterSearch: true
    });

    // Add responsive to jqGrid
    $(window).bind('resize', function () {
        var width = $('.jqGrid_wrapper').width();
        $('#table_list_2').setGridWidth(width);
    });
});